package kislo.dima.task1;

import java.util.Random;

public class MatrixFactory {

	public static Matrix createMatrix(int m, int n, int a, int b) {
		Matrix matrix = new Matrix(m, n);
		for (int i = 0; i < m; i++)
			for (int j = 0; j < n; j++)
				matrix.setElement(i, j, Randomize(a, b));
		return matrix;
	}
	
	private static int Randomize(int a, int b) {
		int c = 0;
		if (a <= b) {
			boolean flag = true;
			while (flag) {
				c = new Random().nextInt(b - a);
				c += a;
				if ((c >= a) && (c <= b))
					flag = false;
			}
		} else {
			System.out.println("The range is incorrectly entered!!!");
			System.exit(0);
		}
		
		return c;
		
	}
}
